import Mock from 'mockjs'
const category = Mock.mock({
    'list|10': [{
        "id|+1": 1,
        "categoryName": "商品分类@id"
    }]
})
const goods = Mock.mock({
    'list|30': [{
        "id|+1": 1,
        "tenantId": "2",
        "creatorId": "3",
        "operatorId": "5",
        "createTime": "@date()",
        "updateTime": "@date()",
        "delTeg": "1",
        "materialNO": "000DD@id",
        "materialName": "商品@id",
        "materialImages": "@Image('100x40','#c33', '#ffffff','小可爱')",
        "barCode": "20125423",
        "categoryCode": "3",
        "abcCategory": "a",
        "brandId": "1",
        "goods_sku": "300ml",
        "units": "吨",
        'batchCode': '0011@id',
        'goods_num|+1': 100,
        'warehousing_time': '@date()'
    }]
})
export default [

    // 商品分类
    {
        url: '/material/category/getAll',
        type: 'post',
        response: config => {
            return {
                code: 20000,
                data: category.list
            }
        }
    },
    //获取商品信息列表
    {
        url: '/material/getPageList',
        type: 'post',
        response: config => {
            let { pageSize = 10, currentPage = 1 } = config.body
            const total = goods.list.length
            let list = goods.list.slice(pageSize * (currentPage - 1), currentPage * pageSize)
            return {
                code: 20000,
                data: {
                    list,
                    currentPage,
                    pageSize,
                    totalCount: total,
                    totalPages: (total + pageSize - 1) / pageSize,
                }
            }
        }
    },
    //删除商品
    {
        url: '/material/del',
        type: 'post',
        response: config => {
            const { id } = config.body
            if (!id) {
                return {
                    code: 403,
                    msg: '删除失败',
                    data: null
                }
            }
            return {
                code: 20000,
                msg: '处理成功',
                data: id
            }
        }
    },
    //新增商品
    {
        url: '/material/add',
        type: 'post',
        response: config => {
            return {
                code: 20000,
                msg: '新增成功',
            }
        }
    },
    //修改商品
    {
        url: '/material/editor',
        type: 'post',
        response: config => {
            return {
                code: 20000,
                msg: '修改成功',
            }
        }
    },
]